package com.onesports.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: HUANG GY.
 * @Date: 2020/6/19 11:55
 * @Description: odf rabbitMq消息发送配置
 */
@Configuration
public class OdfRabbitmqConfig {

    @Value("${spring.rabbitmq.exchange-name}")
    private String exchageName ;

    @Value("${spring.rabbitmq.queue-name}")
    private String queueName ;

    /**
     *  生成一个本身自身的队列
     * @return
     */
    @Bean
    public Queue queue() {
        return new Queue(queueName);
    }

    /**
     * 交换机
     * @return
     */
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(exchageName);
    }

    /**
     *  交换机和队列的绑定
     * @return
     */
    @Bean
    Binding bindingExchangeC() {
        return BindingBuilder.bind(queue()).to(fanoutExchange());
    }
}

